<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="">
        <input type="text" placeholder="请输入账号">
        <input type="password" placeholder="请输入密码">
        <!-- <input type="button" value="btn"> -->
        <input type="submit" value="btn">
    </form>

    <hr>

    <!-- <form action="#">
        test
        <input type="submit" value="btn">
    </form> -->


    <!-- <a href="http://www.baidu.com" id="linkEle">超链接</a> -->

    <script>
        let regId = /^[a-zA-Z][a-zA-Z0-9]{5,17}$/;
        let regPwd = /^[a-zA-Z0-9]{6}$/;

        let arr = [
            { id: "zhangsan", password: '123' },
            { id: 'lisi', password: '456' }
        ];

        const ipt = document.querySelectorAll("input")[0];// 账号框
        const pwd = document.querySelectorAll("input")[1];//密码框
        const btn = document.querySelector("[type='submit']");//按钮

        btn.onclick = function (event) {
            let id = ipt.value, passowd = pwd.value;
            if (regId.test(id) && regPwd.test(passowd)) {
                arr.push({ id, passowd });
                console.log(arr);
            } else {
                event.preventDefault();
                console.log(886);
            }
        }

        // linkEle.onclick = function (event) {
        //     event.preventDefault();// 阻止默认行为
        // }



        // let reg = /a/; // 有 a 才行
        // let str = 'bbbc';
        // let result = reg.test(str);
        // console.log(result);

        // 四川邮编 610000-646000
        // let reg = /6[1234][0-9][0-9][0-9][0-9]/;
        // let reg = /6[1234][0-9]{4}/;
        // let reg = /^6[1234][0-9]{4}$/;
        // let reg = /^6[1234][0-6][0-9]{3}$/;
        // let reg = /6[1234]\d{4}/;
        // let str = '647656';
        // let result = reg.test(str);
        // console.log(result);

        // QQ号 10000 号开始的 5-12
        // let reg = /^[1-9][0-9]{4,11}$/;
        // let str = '263481212463634524323532523';
        // let result = reg.test(str);
        // console.log(result);

        // 账号 首字母字母 6-18位 密码 6 位
        // let regId = /^[a-zA-Z][a-zA-Z0-9]{5,17}$/;
        // let regPwd = /^[a-zA-Z0-9]{6}$/;

        // let arr = [
        //     { id: "zhangsan", password: '123' },
        //     { id: 'lisi', password: '456' }
        // ];

        // const ipt = document.querySelectorAll("input")[0];// 账号框
        // const pwd = document.querySelectorAll("input")[1];//密码框
        // const btn = document.querySelector("[type='button']");//按钮


        // btn.onclick = function () {
        //     let id = ipt.value, passowd = pwd.value;
        //     if (regId.test(id) && regPwd.test(passowd)) {
        //         arr.push({ id, passowd });
        //         console.log(arr);
        //     } else {
        //         console.log(886);
        //     }
        // }



        /*
            获取用户输入的 value
            let reult=正则.test(str)
            if(reult){
                arr.push();
            }else{
                log(不符合要求)
            }
        */

        /*
            .com
            .cn
            .app
            .net
            .
        */



    </script>
</body>

</html>